#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

void m_get_error(int errnum, char *buf, size_t buflen)
{
    if (NULL == buf)
    {
        fprintf(stderr, "error buffer is null.\n");
        return;
    }

    if (strerror_r(errnum, buf, buflen))
    {
        /* strerror_r unknown errors */
        switch (errno)
        {
            case EINVAL:
                fprintf(stderr, "The value of errnum is not a valid error number.\n");
                break;
            case ERANGE:
                fprintf(stderr, "Insufficient storage was supplied to contain the "
                        "error description string.\n");
                break;
            default:
                break;
        }
    }
    return;
}
